package com.OjSystem.system.service.Impl;

import com.OjSystem.system.domain.SysUser;
import com.OjSystem.system.mapper.SysUserMapper;
import com.OjSystem.system.service.ISysUserService;
import com.OjSystem.system.utils.BCryptUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SysUserServiceImpl implements ISysUserService {

    @Autowired
    private SysUserMapper sysUserMapper;

    @Override
    public boolean login(String userAccount, String password) {
        QueryWrapper<SysUser> sysUserQueryWrapper = new QueryWrapper<>();
        sysUserQueryWrapper.eq("user_account",userAccount);
        SysUser sysUser = sysUserMapper.selectOne(sysUserQueryWrapper);
        if (sysUser == null) {
            return false;
        }

        if(!BCryptUtils.matchesPassword(password,sysUser.getPassword())){
            return false;
        }
        return true;
    }
}
